// pages/forward/index.js
var app = getApp();
var Util = require('../../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    qr_code: '',
    images: {},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showLoading({ title: '生成中', mask: true })
    var that = this;
    that.setData({ qr_code: options.code_url, id: options.id, pages: options.pages, })
  },
  // 图片大小
  imageLoad: function (e) {
    var $width = e.detail.width,    //获取图片真实宽度
      $height = e.detail.height,
      ratio = $width / $height;    //图片的真实宽高比例
    var viewWidth = 750,           //设置图片显示宽度，左右留有16rpx边距
      viewHeight = 750 / ratio;    //计算的高度值
    var image = this.data.images;
    //将图片的datadata-index作为image对象的key,然后存储图片的宽高值
    image = {
      width: viewWidth,
      height: viewHeight
    }
    console.log(image);
    this.setData({
      images: image
    })
    wx.hideLoading();
  },

  // 查看分享图片
  look_img: function () {
    var that = this;
    wx.previewImage({
      urls: [that.data.qr_code], // 需要预览的图片http链接列表
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    var that = this;
    var title_text = ['手快有，手慢无', '口快有，口慢无', '玩这个不是用手，是用嘴', '有钱好好说',];
    var num = Math.floor(Math.random() * 4 + 0);
    var url;
    if (that.data.pages == 0)//语音
      url = '/pages/voice_box/parcel_detail/index?code_url=' + that.data.qr_code + '&id=' + that.data.id;
    if (that.data.pages == 1)//猜对
      url = '/pages/voice_box/guess/index?code_url=' + that.data.qr_code + '&id=' + that.data.id;

    return {
      title: title_text[num],
      path: url,
      success: function (res) {
        // 转发成功
        prompt('转发成功', 'success')
      },
      fail: function (res) {
        // 转发失败
        prompt('转发失败', 'loading')
        
      },
    }
  }
})


function prompt(text, status) {
  //提示信息
  wx.showToast({
    title: text,
    icon: status,
    duration: 1200,
  })
}